package com.ymatou.iapi.csim.testcase;

import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.IncrWorkOrdersBean;
import com.ymatou.iapi.csim.parameter.SendMessageCSBean;
import com.ymatou.iapi.csim.service.IncrWorkOrdersCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_cssession;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.EnvSetup;
/**
*会话工单数加1
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_IncrWorkOrders{
	private static IncrWorkOrdersBean incrworkordersBean;
	private static IncrWorkOrdersCall incrworkordersCall;
	private CsimCallService service=new CsimCallService();
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private Integer userId=Integer.parseInt(EnvSetup.getData("userId_IM").toString());
	private static ymt_cssessionWapper csSessionWapper=new ymt_cssessionWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("会话工单数加1");
	}

	@Before
	public void caseUp() {
		incrworkordersBean=new IncrWorkOrdersBean();
		incrworkordersCall=new IncrWorkOrdersCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(incrworkordersCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_IncrWorkOrders_001() {
		Logger.start(true,"会话工单数加1");
		try {
			//客服上线
			service.getOnlineCS(csId);
			//打开会话
			ymt_cssession cssession=service.getOpenSession(csId,userId);
			//发消息
			SendMessageCSBean sendMessageCSBean=service.setSendMessageCSBean();
			sendMessageCSBean.setSessionId(cssession.getId());
			sendMessageCSBean.setCsId(csId);
			sendMessageCSBean.setUserId(userId);
			service.setSendMessageCSCall(sendMessageCSBean);
			
			ymt_cssession session1=csSessionWapper.selectBysessionNumber(Arrays.asList(cssession.getSessionNumber())).get(0);
			
			incrworkordersBean.setSessionId(cssession.getSessionNumber());
			incrworkordersCall.setData(incrworkordersBean);
			incrworkordersCall.callService();		
			
			Logger.verifyEquals("200", incrworkordersCall.getStatus(), "验证status");
			Logger.verifyEquals("", incrworkordersCall.getMsg(), "验证Msg");
			Logger.verifyEquals(true, incrworkordersCall.getResult().getBoolean("Success"), "验证Msg");
			ymt_cssession session2=csSessionWapper.selectBysessionNumber(Arrays.asList(cssession.getSessionNumber())).get(0);
			Logger.verifyEquals(1, session2.getWorkOrders()-session1.getWorkOrders(), "验证会话工单数加1");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}